<?php
namespace Admin\Controller;
use Think\Controller;
class AdminController extends Controller{
    public function Admin(){
        $username = cookie('username');
        $this->assign('username',$username);

        $ajax = I("get.");
        $where=array();
        if($ajax[username]){
            $where['username']=array('LIKE','%'.$ajax[username].'%');
        }
        $User = M('Admin'); // 实例化User对象
        $count      = $User->where($where)->count();
        // 查询满足要求的总记录数
        $Page       = new \Think\Page($count,3);
        // 实例化分页类 传入总记录数和每页显示的记录数(3)
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $show       = $Page->show();
        // 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $User->where($where)->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);
        // 赋值数据集
        $this->assign('page',$show);
        // 赋值分页输出
        $this->display();
    }

    public function Del(){
        $ajax = I("post.");
        $id = rtrim($ajax['id'],",");
        $Del = M('Admin');
        $rs = $Del->where('id="'.$id.'"')->delete();
        if($rs === false){
            $this->ajaxReturn(array('flag'=>0));
        }else{
            $this->ajaxReturn(array('flag'=>1));
        }
    }
    public function SaveAdmin(){
        $username = cookie('username');
        $this->assign('username',$username);

        $getId = I('get.');
        $id = $getId['id'];
        $this->assign('id',$id);
        $SelectUN = M('Admin');
        $rs = $SelectUN->where('id="'.$id.'"')->select();
        $name = $rs[0]['username'];
        $this->assign('name',$name);
        $email = $rs[0]['email'];
        $this->assign('email',$email);
        $this->display();
    }public function doSaveAdmin(){
    $post = $_POST;
    $id = $post['id'];
    $Save = M('Admin');
    $rs = $Save->where('id="'.$id.'"')->save($post);
    if($rs){
        $this->success("修改成功！",U('Admin/Admin/Admin'));
    }else{
        $this->error("修改失败！",U('Admin/Admin/Admin'));
    }
}

}

